package de.tsystems.jsfdict.webservice;

import de.tsystems.jsfdict.api.LanguageService;
import de.tsystems.jsfdict.api.TranslationService;
import de.tsystems.jsfdict.api.WordService;
import org.springframework.transaction.annotation.Transactional;

import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.ext.Provider;

@Provider
@Path("/translation")
@Produces({MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON})
public interface TranslationManipulationService {

    TranslationService getTranslationService();

    LanguageService getLanguageService();

    WordService getWordService();

    void setTranslationService(TranslationService translationService);

    void setLanguageService(LanguageService languageService);

    void setWordService(WordService wordService);

    @GET
    @Produces("text/plain")
    @Transactional(readOnly = true)
    String greetUser();

    @GET
    @Path("/count")
    @Produces("text/plain")
    @Transactional(readOnly = true)
    String countTranslations();

    @POST
    @Produces("text/plain")
    @Consumes("application/json")
    @Transactional
    @Path("/add")
    String add(TranslationInfo info);

    public static class TranslationInfo {
        private String leftWord;
        private String rightWord;
        private String leftLanguage;
        private String rightLanguage;

        public TranslationInfo() {}

        public TranslationInfo(String leftWord, String rightWord, String leftLanguage, String rightLanguage) {
            this.leftWord = leftWord;
            this.rightWord = rightWord;
            this.leftLanguage = leftLanguage;
            this.rightLanguage = rightLanguage;
        }

        public String getLeftWord() {
            return leftWord;
        }

        public void setLeftWord(String leftWord) {
            this.leftWord = leftWord;
        }

        public String getRightWord() {
            return rightWord;
        }

        public void setRightWord(String rightWord) {
            this.rightWord = rightWord;
        }

        public String getLeftLanguage() {
            return leftLanguage;
        }

        public void setLeftLanguage(String leftLanguage) {
            this.leftLanguage = leftLanguage;
        }

        public String getRightLanguage() {
            return rightLanguage;
        }

        public void setRightLanguage(String rightLanguage) {
            this.rightLanguage = rightLanguage;
        }
    }
}
